/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package component;

import ddf.minim.AudioPlayer;
import processing.core.PApplet;

/**
 *
 * @author biron
 */
public class ButtonForward extends AButton
{
  private boolean       _invert;
  private boolean       _pressed;
  private AudioPlayer   _player;
  
  public ButtonForward(int x, int y, int hw, int hh, PApplet app, AudioPlayer player)
  {
    super(x, y, hw, hh, app);
    _player = player;
    _invert = false;
  }
  
  public void update()
  {
    // if the forward button is currently being _pressed
    if (_pressed)
    {
      // get the current position of the _player
      int pos = _player.position();
      // if the _player's position is more than 40 milliseconds from the end of the _player
      if ( pos < _player.length() - 40 )
      {
        // forward the _player by 40 milliseconds
        _player.skip(40);
      }
      else
      {
        // otherwise, cue the _player at the end of the _player
        _player.cue( _player.length() );
      }
      // start the _player playing
      _player.play();
    }
  }
  
  public void mousePressed()
  {
    _pressed = pressed();
    if ( _pressed ) 
    {
      _invert = true;      
    }
  }
  
  public void mouseReleased()
  {
    _pressed = false;
    _invert = false;
  }

  public void draw()
  {
    if ( _invert )
    {
      _app.fill(255);
      _app.stroke(0);
    }
    else
    {
      _app.noFill();
      _app.stroke(255);
    }
    
    _app.rect(x - hw, y - hh, hw*2, hh*2);
    
    if ( _invert )
    {
      _app.fill(0);
      _app.stroke(255);
    }
    else
    {
      _app.fill(255);
      _app.noStroke();
    }
    
    _app.triangle(x, y, x - hw/2, y - hh/2, x - hw/2, y + hh/2);
    _app.triangle(x, y - hh/2, x, y + hh/2, x + hw/2, y);    
  }  

    /**
     * @param _player the _player to set
     */
    public void setPlayer(AudioPlayer _player) {
        this._player = _player;
    }
}